/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jdAdministrarActividades.java
 *
 * Created on 24-ago-2010, 17:19:47
 */

package Licitaciones;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.MiTablePrint;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.helper.Utiles_Tabla;
import administracion.propiedades.Propiedades;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import suministros.ejb30.entity.DetalleLicitacionActividad;
import java.math.BigDecimal;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.ELProperty;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;
import suministros.ejb30.TO.DetalleOrdenTO;
import suministros.ejb30.TO.LicitacionActividadTO;
/**
 *
 * @author Diana
 */
public class jdAdministrarActividades extends javax.swing.JDialog {
    jdAdministrarLicitacion padre;
    public List<LicitacionActividadTO> actividades;
    public List<LicitacionActividadTO> actividadesagregar;
    private BindingGroup bindingGroup;
    private JTableBinding jTableBinding;
    jdAdministrarLicitacion reg;
    String codigo;
    String suministro;
    String descripcion;
    int filaElegida;
    boolean estado;
    BigDecimal montoTotalSumi;
    BigDecimal montoTotal;
    BigDecimal montoTotalUtilizado;
    java.awt.Frame parent;
    /** Creates new form jdAdministrarActividades */
    public jdAdministrarActividades(jdAdministrarLicitacion padre,java.awt.Frame parent, boolean modal, String codigo, String suministro, String descripcion, int filaElegida, BigDecimal montoTotalSumi) {
        super(parent, modal);
        initComponents();
        this.padre=padre;
        this.parent=parent;
        this.filaElegida=filaElegida;
        this.codigo=codigo;
        this.suministro=suministro;
        this.descripcion=descripcion;
        this.jtfLicitacion.setText(codigo);
        this.jtfSuministro.setText(suministro);
        this.jtfDescripcion.setText(descripcion);
        this.jtfLicitacion.setEditable(false);
        this.jtfSuministro.setEditable(false);
        this.jtfDescripcion.setEditable(false);
        this.montoTotalSumi=montoTotalSumi;
        actividadesagregar= new ArrayList<LicitacionActividadTO>();

        try {
            obtenerActividades();
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarActividades.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    void setPadreDetalle(jdAdministrarLicitacion reg){
        this.reg=reg;
    }
    public void obtenerActividades() throws Exception{
         actividades = GestionPedidosDelegate.getInstance().getActividadesPorLicitacionEspecifica(codigo,suministro);
         cargarTabla();
    }
      public void cargarTabla() throws Exception{

        this.bindingGroup = new BindingGroup();
        this.bindingGroup.addBindingListener(new AbstractBindingListener() {
                       @Override public void synced(Binding binding) {
                        try{
                            if(!actividades.isEmpty()){
                                int selec=jtActividades.getSelectedRow();
                                if(selec>0){
                                     LicitacionActividadTO detaord_aux= actividades.get(jtActividades.convertRowIndexToModel(selec));
                                    detaord_aux.setCantidad_disponible(detaord_aux.getCantidad().subtract(detaord_aux.getCantidadAdquiridaActual()).setScale(2));
                                    detaord_aux.setCantidad(detaord_aux.getCantidad().setScale(2));
                                    cargarTabla();
                                }
                               
                            }

                    }catch(ArrayIndexOutOfBoundsException ex){
                    }
                        catch(Exception e){
                        e.printStackTrace();
                    }

                }
            });

        this.jTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, this.actividades, this.jtActividades);

        JTableBinding.ColumnBinding columnBinding0 = this.jTableBinding.addColumnBinding(ELProperty.create("${id_tipo_actividad}"));

        columnBinding0.setColumnName("Tipo");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        JTableBinding.ColumnBinding columnBinding1 = this.jTableBinding.addColumnBinding(ELProperty.create("${codigo_item}"));

        columnBinding1.setColumnName("Item");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        JTableBinding.ColumnBinding columnBinding2 = this.jTableBinding.addColumnBinding(ELProperty.create("${descripcion_actividad}"));

        columnBinding2.setColumnName("Actividad");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(false);

        JTableBinding.ColumnBinding columnBinding3 = this.jTableBinding.addColumnBinding(ELProperty.create("${unidad}"));

        columnBinding3.setColumnName("Unidad");
        columnBinding3.setColumnClass(String.class);
        columnBinding3.setEditable(false);

        JTableBinding.ColumnBinding columnBinding4 = this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad}"));

        columnBinding4.setColumnName("Cantidad");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(true);

        JTableBinding.ColumnBinding columnBinding5= this.jTableBinding.addColumnBinding(ELProperty.create("${costo_unitario}"));;

        columnBinding5.setColumnName("Cost.Unit");
        columnBinding5.setColumnClass(BigDecimal.class);
        columnBinding5.setEditable(false);

         JTableBinding.ColumnBinding columnBinding6= this.jTableBinding.addColumnBinding(ELProperty.create("${cantidad_disponible}"));;

        columnBinding6.setColumnName("Cant.Dispo");
        columnBinding6.setColumnClass(BigDecimal.class);
        columnBinding6.setEditable(false);

        JTableBinding.ColumnBinding columnBinding7= this.jTableBinding.addColumnBinding(ELProperty.create("${cantidadAdquiridaActual}"));;

        columnBinding7.setColumnName("Cant.Adq");
        columnBinding7.setColumnClass(BigDecimal.class);
        columnBinding7.setEditable(false);

        JTableBinding.ColumnBinding columnBinding8= this.jTableBinding.addColumnBinding(ELProperty.create("${monto_adquirido}"));;

        columnBinding8.setColumnName("Mont.Adq");
        columnBinding8.setColumnClass(BigDecimal.class);
        columnBinding8.setEditable(false);


        this.bindingGroup.addBinding(this.jTableBinding);
        this.bindingGroup.bind();

        int[] porcentajes= {10,5,35,8,8,8,8,8,10};
        try {
               Utiles_Tabla.definirAnchoColumnasJTable(this.jtActividades, porcentajes);
              //MiTablePrint.autoSizeTableColumns(this.jtActividades);
        } catch (Exception ex) {
            Logger.getLogger(jdAdministrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(!actividades.isEmpty()){
            this.jtfTotal.setText(actividades.size()+"");
            montoTotal=BigDecimal.ZERO;
            montoTotalUtilizado=BigDecimal.ZERO;
            for (int i=0; i<actividades.size(); i++) {
            BigDecimal monto= new BigDecimal(Float.parseFloat(this.jtActividades.getValueAt(i, 4).toString())*Float.parseFloat(this.jtActividades.getValueAt(i, 5).toString()));
            BigDecimal montoutilizado= new BigDecimal(Float.parseFloat(this.jtActividades.getValueAt(i, 5).toString())*Float.parseFloat(this.jtActividades.getValueAt(i, 7).toString()));
            montoTotal= montoTotal.add(monto);
            montoTotalUtilizado= montoTotalUtilizado.add(montoutilizado);
            }
            montoTotal.setScale(2);
            montoTotalUtilizado.setScale(2);
            this.jtfMonto.setText(montoTotal.setScale(2)+"");
            this.jtfMontoUtilizado.setText(montoTotalUtilizado.setScale(2)+"");
            this.jbAceptar.setEnabled(true);
        }
    }
    public   void cerrar(){
      int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
      "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
            if(res==javax.swing.JOptionPane.YES_OPTION){
                    this.dispose();

         }
      }
    void agregaActividad(LicitacionActividadTO detalle) throws Exception {
       try {
          if (verificaNoExisteSuministro(detalle)) {
            this.actividades.add(detalle);
            this.actividadesagregar.add(detalle);
            this.cargarTabla();
          } else {
            throw new Exception("La actividad con el codigo de item:" + detalle.getCodigo_item().trim() + "\n  y el tipo de actividad :" + detalle.getId_tipo_actividad() + " \n ya fue ingresado");
          }
        } catch (Exception e) {
          throw e;
        }
    }
    private boolean verificaNoExisteSuministro(LicitacionActividadTO detalle) {
    boolean retorno = true;
    for (LicitacionActividadTO det : this.actividades) {
      
      if (det.getCodigo_item().equalsIgnoreCase(detalle.getCodigo_item())   && det.getId_tipo_actividad()==detalle.getId_tipo_actividad()) {
        retorno = false;
        break;
      }
    }
    return retorno;
  }

    public void modificarActividad(){
         List<DetalleLicitacionActividad> lista= new ArrayList();
          for (LicitacionActividadTO detalle: this.actividades) {
          DetalleLicitacionActividad detall = new DetalleLicitacionActividad(this.jtfLicitacion.getText(),this.jtfSuministro.getText(), detalle.getId_tipo_actividad(), detalle.getCodigo_item());
          detall.setDescripcion(detalle.getDescripcion_actividad());
          detall.setTipoUnidad(detalle.getUnidad());
          detall.setCantidadAdquirida(detalle.getCantidadAdquiridaActual());
          detall.setCantidad(detalle.getCantidad());
          detall.setCostoUnitario(detalle.getCosto_unitario());
          detall.setMontoTotal(detall.getCantidad().multiply(detall.getCostoUnitario()));
          detall.setMontoAdquirido(detalle.getCantidadAdquiridaActual().multiply(detall.getCostoUnitario()));
          lista.add(detall);
         }
          List<DetalleLicitacionActividad> listaagregar= new ArrayList();
          for (LicitacionActividadTO detalle: this.actividadesagregar) {
          DetalleLicitacionActividad detall = new DetalleLicitacionActividad(this.jtfLicitacion.getText(),this.jtfSuministro.getText(), detalle.getId_tipo_actividad(), detalle.getCodigo_item());
          detall.setDescripcion(detalle.getDescripcion_actividad());
          detall.setTipoUnidad(detalle.getUnidad());
          detall.setCantidadAdquirida(detalle.getCantidadAdquiridaActual());
          detall.setCantidad(detalle.getCantidad());
          detall.setCostoUnitario(detalle.getCosto_unitario());
          detall.setMontoTotal(detall.getCantidad().multiply(detall.getCostoUnitario()));
          detall.setMontoAdquirido(detalle.getCantidadAdquiridaActual().multiply(detall.getCostoUnitario()));
          listaagregar.add(detall);
         }
        try {
            GestionPedidosDelegate.getInstance().modificarActividades(Propiedades.getUsuario(),Propiedades.getMac(),lista,listaagregar, montoTotalSumi);
        } catch (Exception ex) {
            Logger.getLogger(jdAgregarActividadesMod.class.getName()).log(Level.SEVERE, null, ex);
        }
     }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtActividades = new javax.swing.JTable();
        this.jtActividades.getTableHeader().setReorderingAllowed(false) ;
        jtfLicitacion = new javax.swing.JTextField();
        jtfDescripcion = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfSuministro = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jbCancelar = new javax.swing.JButton();
        jbAceptar = new javax.swing.JButton();
        jbAgregarDetalle = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtfTotal = new javax.swing.JTextField();
        jtfMonto = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtfMontoUtilizado = new javax.swing.JTextField();
        jbtImprimir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ADMINISTRAR ACTIVIDADES");

        jtActividades.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tipo", "Item", "Actividad", "Unidad", "Cantidad", "Precio", "Cantidad Disponible", "Cantidad Adquirida", "Monto Disponible"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jtActividades);

        jtfLicitacion.setFont(new java.awt.Font("Arial", 0, 12));
        jtfLicitacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtfLicitacionKeyPressed(evt);
            }
        });

        jtfDescripcion.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("DESC. SUMINISTRO:");

        jtfSuministro.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel1.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel1.setText("COD. LICITACION:");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel2.setText("COD. SUMINISTRO:");

        jbCancelar.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jbCancelar.setMnemonic('C');
        jbCancelar.setText("CERRAR");
        jbCancelar.setToolTipText("Cancelar la Operacion");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jbCancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbCancelarKeyPressed(evt);
            }
        });

        jbAceptar.setFont(new java.awt.Font("Arial", 0, 12));
        jbAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbAceptar.setMnemonic('A');
        jbAceptar.setText("ACEPTAR");
        jbAceptar.setToolTipText("Registrar el pedido");
        jbAceptar.setEnabled(false);
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAceptarActionPerformed(evt);
            }
        });
        jbAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbAceptarKeyPressed(evt);
            }
        });

        jbAgregarDetalle.setFont(new java.awt.Font("Arial", 0, 12));
        jbAgregarDetalle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/add.png"))); // NOI18N
        jbAgregarDetalle.setMnemonic('G');
        jbAgregarDetalle.setText("AGREGAR");
        jbAgregarDetalle.setToolTipText("Agregar un detalle al pedido");
        jbAgregarDetalle.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbAgregarDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarDetalleActionPerformed(evt);
            }
        });
        jbAgregarDetalle.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbAgregarDetalleKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel5.setText("TOTAL DE ACTIVIDADES:");

        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setText("MONTO TOTAL:");

        jtfTotal.setFont(new java.awt.Font("Arial", 0, 12));
        jtfTotal.setEnabled(false);

        jtfMonto.setFont(new java.awt.Font("Arial", 0, 12));
        jtfMonto.setEnabled(false);

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setText("MONTO UTILIZADO:");

        jtfMontoUtilizado.setFont(new java.awt.Font("Arial", 0, 12));
        jtfMontoUtilizado.setEnabled(false);

        jbtImprimir.setFont(new java.awt.Font("Arial", 1, 12));
        jbtImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/document_print.png"))); // NOI18N
        jbtImprimir.setText("IMPRIMIR");
        jbtImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtImprimirActionPerformed(evt);
            }
        });
        jbtImprimir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtImprimirKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfLicitacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                            .addComponent(jtfSuministro, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(34, 34, 34)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbAgregarDetalle)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfMontoUtilizado)
                            .addComponent(jtfMonto)
                            .addComponent(jtfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 185, Short.MAX_VALUE)
                        .addComponent(jbAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtImprimir)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbCancelar))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 774, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfLicitacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSuministro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jtfDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbAgregarDetalle)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jtfMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtfMontoUtilizado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbCancelar)
                        .addComponent(jbtImprimir)
                        .addComponent(jbAceptar)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtfLicitacionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfLicitacionKeyPressed

}//GEN-LAST:event_jtfLicitacionKeyPressed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
 
        cerrar();
}//GEN-LAST:event_jbCancelarActionPerformed

    private void jbCancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbCancelarKeyPressed
       
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbCancelar.doClick();
        }
}//GEN-LAST:event_jbCancelarKeyPressed

    private void jbAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAceptarActionPerformed

      int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro que desea modificar las actividades?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
         if(res==javax.swing.JOptionPane.YES_OPTION){
             if(montoTotalSumi.compareTo(montoTotal)!=0){

                int res1 = javax.swing.JOptionPane.showConfirmDialog( this,"El monto total migrado no coincide con el ingresado en la licitacion \n ¿Desea modificar el monto del suministro en la licitacion?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
                 if(res1==javax.swing.JOptionPane.YES_OPTION){
                    montoTotalSumi=montoTotal;
                    estado=true;
                 }
                 else
                    estado=false;
            }
            else{
                estado=true;
            }
             if(estado){
                try {
                this.modificarActividad();
                Utiles_MensajesDialogo.mensajeExito();
                reg.jtDetalleSuministro.setValueAt(montoTotalSumi, filaElegida, 5);
                reg.jtDetalleSuministro.setValueAt(montoTotalSumi,filaElegida, 4);
                this.jbAceptar.setEnabled(false);
                } catch (Exception ex) {
                    Logger.getLogger(jifRegistrarLicitacion.class.getName()).log(Level.SEVERE, null, ex);
                    Utiles_MensajesDialogo.mensajeError("No se puedo modificar las actividades");
               }
             }
             else{
                  Utiles_MensajesDialogo.mensajeAlerta("Los montos totales no coinciden");
             }

         }

}//GEN-LAST:event_jbAceptarActionPerformed

    private void jbAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbAceptarKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAceptar.doClick();
        }
}//GEN-LAST:event_jbAceptarKeyPressed

    private void jbAgregarDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarDetalleActionPerformed
  
            jdAgregaDetalleActividadMod jdAgregaDetalle=new jdAgregaDetalleActividadMod(this,parent,true,new BigDecimal(jtfMonto.getText()));
            jdAgregaDetalle.setLocationRelativeTo(null);
            jdAgregaDetalle.setPadreDetalle(this);
            jdAgregaDetalle.setVisible(true);
            jdAgregaDetalle.setTitle("Agregar detalles de licitacion");
            this.jbAceptar.setEnabled(true);
}//GEN-LAST:event_jbAgregarDetalleActionPerformed

    private void jbAgregarDetalleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbAgregarDetalleKeyPressed
      
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbAgregarDetalle.doClick();
        }
}//GEN-LAST:event_jbAgregarDetalleKeyPressed

    private void jbtImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtImprimirActionPerformed

        MiTablePrint pp = new MiTablePrint(this.jtActividades, "ACTIVIDADES DE LICITACIONES", "DETALLE DE ACTIVIDADES DE UNA LICITACION");
        pp.showPrintPreview();
    }//GEN-LAST:event_jbtImprimirActionPerformed

    private void jbtImprimirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtImprimirKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtImprimir.doClick();
        }
}//GEN-LAST:event_jbtImprimirKeyPressed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbAgregarDetalle;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbtImprimir;
    private javax.swing.JTable jtActividades;
    private javax.swing.JTextField jtfDescripcion;
    private javax.swing.JTextField jtfLicitacion;
    public javax.swing.JTextField jtfMonto;
    private javax.swing.JTextField jtfMontoUtilizado;
    private javax.swing.JTextField jtfSuministro;
    private javax.swing.JTextField jtfTotal;
    // End of variables declaration//GEN-END:variables

}
